#ifndef CAMERA_H
#define CAMERA_H

#include "MegaMan.h"
#include "UtilFunctions.h"
#include "GlobalSettings.h"
#include "MathMisc.h"

class Camera
{
	public:
		Camera();
		Camera(Position Properties, MegaMan * Mega);
		void setCamera(Position Properties, MegaMan * Mega);

		void Update();
		void HandleInput();
		void Move();
		
	private:
		Position properties;
		Position adjust;
		MegaMan *following;
};

Camera::Camera()
{
	following = 0;
}

Camera::Camera(Position Properties, MegaMan * Mega)
{
	properties = Properties;
	following = Mega;
}

void Camera::setCamera(Position Properties, MegaMan * Mega)
{
	properties = Properties;
	following = Mega;
}

void Camera::Update()
{

	// Move Camera to new Location
	Move();

	// Point the camera at MegaMan
	Position location = following->location;
	location.x += properties.r*sin(toRadian(properties.angle));
	location.y += properties.y;
	location.z += properties.r*cos(toRadian(properties.angle));
	gluLookAt(location.x, location.y, location.z, following->location.x, properties.z, following->location.z, 0, 1, 0);
}

void Camera::HandleInput()
{
	if ( KeyDown['a'] || KeyDown['A'])
		adjust.angle = -CSPEED;
	else if ( KeyDown['d'] || KeyDown['D'] )
		adjust.angle = CSPEED;
	else
		adjust.angle = 0;

	if ( KeyDown['w'] || KeyDown['W'] )
		adjust.y = CSPEED;
	else if ( KeyDown['s'] || KeyDown['S'] )
		adjust.y = -CSPEED;
	else
		adjust.y = 0;

	if ( KeyDown['q'] || KeyDown['Q'] )
		adjust.z = -CSPEED;
	else if ( KeyDown['e'] || KeyDown['E'] )
		adjust.z = CSPEED;
	else adjust.z = 0;
	
	
}

void Camera::Move()
{
	properties += adjust;
	following->cameraMod = properties.angle-270;
}

#endif
